package com.activities;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.Animations.AnimUtil;
import com.Managers.DirManagerClass;
import com.Managers.FragmentManagerClass;
import com.Managers.ThemeManager;
import com.Managers.UserManagerClass;
import com.shareup.R;
import com.utils.AppConstant;


public class ActivityVerifyLogin extends Activity {

    private void getIDLogged() {

        Intent intent = new Intent();
        //
        UserManagerClass usm = new UserManagerClass(this);
        int res = usm.getIdUser();
        //
        DirManagerClass.createDirectorios();
        //
        if (res == 0) {
            intent.setClass(this, ActivityLogin.class);
        }
        else {
            UserManagerClass.UserLogged = usm.getInfo();
            intent.setClass(this, ActivityMain.class);
            AppConstant.isFirstTime = false;
        }

        startActivity(intent);
        AnimUtil.getActivityTransition(this, true);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        ThemeManager.setTheme(this);
        setContentView(R.layout.activity_empty);
        super.onCreate(savedInstanceState);

        Bundle extras = getIntent().getExtras();
        if (extras != null) {

            if (extras.getBoolean("logout")) {

                if (FragmentManagerClass.aMain != null)
                    FragmentManagerClass.aMain.finish();

                new UserManagerClass(this).delete();
                new DirManagerClass().deleteUserCache();
                UserManagerClass.UserLogged = null;
                UserManagerClass.UserLocation = null;
            }

        }

        getIDLogged();
    }
}
